package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.SummaryTypeEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ExpenseEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/18 21:01
 * @since v1.0
 */
@Getter
public enum TempExpenseEnum {
    //模板设计展示字段
    OPEN_APP_ID(ExpenseEnum.OPEN_APP_ID),
    EXPENSE_CODE(ExpenseEnum.EXPENSE_CODE),
    REIMBURSEMENT_FORM_ID(ExpenseEnum.REIMBURSEMENT_FORM_ID),
    LINK_REIMBURSEMENT_FORM_HIDE(ExpenseEnum.LINK_REIMBURSEMENT_FORM_HIDE),
    EXPENSE_TYPE(ExpenseEnum.EXPENSE_TYPE),
    CONSUME_CITY(ExpenseEnum.CONSUME_CITY),
    AMOUNT(ExpenseEnum.AMOUNT),
    CONSUME_TIME(ExpenseEnum.CONSUME_TIME),
    FORM_USER_CODE(ExpenseEnum.FORM_USER_CODE),
    FORM_USER_NAME(ExpenseEnum.FORM_USER_NAME),
    PROJECT_NAME(ExpenseEnum.PROJECT_NAME),
    PROJECT_CODE(ExpenseEnum.PROJECT_CODE),
    CUSTOMER_ID(ExpenseEnum.CUSTOMER_ID),
    LINK_CUSTOMER_ID_HIDE(ExpenseEnum.LINK_CUSTOMER_ID_HIDE),
    CONTRACT_ID(ExpenseEnum.CONTRACT_ID),
    LINK_CONTRACT_ID_HIDE(ExpenseEnum.LINK_CONTRACT_ID_HIDE),
    OPPORTUNITY_ID(ExpenseEnum.OPPORTUNITY_ID),
    LINK_OPPORTUNITY_ID_HIDE(ExpenseEnum.LINK_OPPORTUNITY_ID_HIDE),
    APPORTIONED_AMOUNT(ExpenseEnum.APPORTIONED_AMOUNT),
    ADD_TIME(ExpenseEnum.ADD_TIME),
    UPDATE_TIME(ExpenseEnum.UPDATE_TIME),
    CREATOR_ID(ExpenseEnum.CREATOR_ID),
            ;
    /**
     * 费用枚举
     */
    private ExpenseEnum anEnum;

    TempExpenseEnum(ExpenseEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempExpenseEnum> getAllEnum() {
        List<TempExpenseEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initExpenseCode(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.EXPENSE.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.EXPENSE.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(EXPENSE_CODE.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(0);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.EXPENSE_NO));
        fieldAttrEntity.setIsForbidden(0);
    }


    public static void initReimbursementFormId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.REIMBURSEMENT_FORM.getCode());
        fieldAttrEntity.setLinkedText(LINK_REIMBURSEMENT_FORM_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }


    public static void initAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.NONE.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initConsumeTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd");
        fieldAttrEntity.setIsForbidden(0);
    }
    /**
     * 报销人
     *
     * @param fieldAttrEntity
     */
    public static void initFormUserCode(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(FORM_USER_NAME.getAnEnum().getAttr());
        fieldAttrEntity.setIsForbidden(0);
    }


    public static void initCustomerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(LINK_CUSTOMER_ID_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }


    public static void initContractId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CONTRACT.getCode());
        fieldAttrEntity.setLinkedText(LINK_CONTRACT_ID_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }


    public static void initOpportunityId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.SALES_OPPORTUNITY.getCode());
        fieldAttrEntity.setLinkedText(LINK_OPPORTUNITY_ID_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }


    /**
     * 初始化跟进业务
     *
     * @param fieldAttrEntity 字段属性实体
     * @author long.rao
     * @date 2019-02-12 14:09
     */
    public static void initBusinessType(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(XbbRefTypeEnum.SALES_OPPORTUNITY.getName());
        Integer opportunityCode = XbbRefTypeEnum.SALES_OPPORTUNITY.getCode();
        itemPoJo.setValue(opportunityCode.toString());
        itemPoJo.setChecked(true);
        itemPoJos.add(itemPoJo);
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText(XbbRefTypeEnum.CONTRACT.getName());
        Integer contractCode = XbbRefTypeEnum.CONTRACT.getCode();
        itemPoJo1.setValue(contractCode.toString());
        itemPoJo1.setChecked(false);
        itemPoJos.add(itemPoJo1);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getName());
        Integer quotationCode = XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode();
        itemPoJo2.setValue(quotationCode.toString());
        itemPoJo2.setChecked(false);
        itemPoJos.add(itemPoJo2);
        fieldAttrEntity.setItems(itemPoJos);
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("relied");
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    public static void initApportionedAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }



    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
}
